package org.budo.druid.filter.stat;

import com.alibaba.druid.filter.stat.MergeStatFilter;
import com.alibaba.druid.proxy.jdbc.PreparedStatementProxy;
import com.alibaba.druid.proxy.jdbc.StatementProxy;

import lombok.extern.slf4j.Slf4j;

/**
 * @author lmw
 */
@Slf4j
public class BudoMergeStatFilter extends MergeStatFilter {
    private static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS";

    @Override
    public void statementPrepareAfter(PreparedStatementProxy statement) {
        if (null == statement || null == statement.getSql() || statement.getSql().trim().toUpperCase().startsWith(CREATE_TABLE)) {
            log.info("#16 statementPrepareAfter, sql=" + statement.getSql() + ", statement=" + statement);
            return;
        }

        super.statementPrepareAfter(statement);
    }

    @Override
    protected void statementExecuteUpdateBefore(StatementProxy statement, String sql) {
        if (null == statement || null == sql || sql.trim().toUpperCase().startsWith(CREATE_TABLE)) {
            log.info("#27 statementExecuteUpdateBefore, sql=" + sql + ", statement=" + statement);
            return;
        }

        super.statementExecuteUpdateBefore(statement, sql);
    }
}